// 地址管理API服务
import request from "@/common/utils/request.js";

const BASE_URL = "/api/address";

// 创建地址
export const createAddress = (data) => {
  return request({
    url: BASE_URL,
    method: "POST",
    data
  });
};

// 查询地址列表
export const getAddressList = (customerId) => {
  return request({
    url: BASE_URL,
    method: "GET",
    data: {
      customerId: customerId,
    },
  });
};

// 查询单个地址
export const getAddressById = (id) => {
  return request({
    url: `${BASE_URL}/${id}`,
    method: "GET",
  });
};

// 更新地址
export const updateAddress = (id, data) => {
  return request({
    url: `${BASE_URL}/${id}`,
    method: "PUT",
    data,
  });
};

// 删除地址
export const deleteAddress = (id) => {
  return request({
    url: `${BASE_URL}/${id}`,
    method: "DELETE",
  });
};

// 设置默认地址
export const setDefaultAddress = (id, customerId) => {
  return request({
    url: `${BASE_URL}/${id}/default`,
    method: "PUT",
    data: {
      customerId: customerId,
    },
  });
};
